package com.gjy.learning.scala

import scala.io.StdIn

object TableCreationStatementGenerator {
  def main(args: Array[String]): Unit = {
    // 获取表名
    println("请输入表名:")
    val tableName = StdIn.readLine()

    // 获取字段数量
    println("请输入字段数量:")
    val fieldCount = StdIn.readInt()
    StdIn.readLine() // 消耗换行符

    val fields = (1 to fieldCount).map { _ =>
      println("请输入字段名和数据类型，以空格分隔（例如: id INT）:")
      val input = StdIn.readLine()
      val parts = input.split(" ")
      (parts(0), parts(1))
    }

    // 生成建表语句
    val createTableStatement = s"CREATE TABLE $tableName (\n" +
      fields.map { case (fieldName, dataType) => s"  $fieldName $dataType" }.mkString(",\n") +
      "\n);"

    println("生成的建表语句如下:\n")
    println(createTableStatement)
  }
}